/**************************************************************************
* File:            searchtester.h	                                      *
* Description:     TestingVisitor for testing DFS/BFS                     *
* Author:          Zhuk Artsem, 399                                       *
**************************************************************************/

#pragma once

#include "graph.h"
#include "search.h"
#include <vector>
#include <algorithm>

class TestingVisitor : public Visitor{
	std::vector<int> entered, leaved;
public:
	void setGraphSize(int size){
		entered.resize(size);
		leaved.resize(size);
	}

	void reset(){
		std::fill(entered.begin(), entered.end(), 0);
		std::fill(leaved.begin(), leaved.end(), 0);
	}

	void enterVertex(int vertex){
		entered[vertex]++;
	}

	void enterEdge(int from, int to){}

	void leaveEdge(int from, int to){}

	void leaveVertex(int vertex){
		leaved[vertex]++;
	}

	bool isGood(){
		for (int &count:entered)
		if (count != 1)
			return false;

		for (int &count:leaved)
		if (count != 1)
			return false;

		return true;
	}

	bool everyVertexClosed(){
		for (int i = 0; i < entered.size(); ++i)
		if ((entered[i] != leaved[i]) || (entered[i] != 1 && entered[i] != 0))
			return false;
		return true;
	}
};